package JianZhiOffer;

import JianZhiOffer.entity.ListNode;

/**
 * 链表删除一个节点
 * */
class Solution18 {
    public ListNode deleteNode(ListNode head, int val) {
        if (head == null) return null;
        if (head.val == val) return head.next;

        ListNode pre = head;
        ListNode current = head.next;
        while (current != null) {
            if (current.val == val) {
                pre.next = current.next;
                return head;
            }
            pre = current;
            current = current.next;
        }
        return head;

    }
}